<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>$parnet</h2>
      <child></child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const Child2 = {
        template: `
          <div>child2组件</div>
        `,
        mounted() {
          // this.$root表示的是根组件实例
          // 父传子的一种方式
          console.log("child2", this.$root.count);
        },
      };

      const Child = {
        data() {
          return {
            count: 0,
          };
        },
        template: `
          <div>child组件 - {{ count }}</div>
          <child2></child2>
        `,
        mounted() {
          // this.$parent表示的是父组件实例
          // 父传子的一种方式

          // console.log(this.$parent.count);
          this.count = this.$parent.count;
        },
        components: {
          Child2,
        },
      };

      createApp({
        data() {
          return {
            count: 100,
          };
        },
        components: {
          Child,
        },
      }).mount("#app");
    </script>
  </body>
</html>
